package fr.xebia.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import xke.xwfc.biz.UnknowCallGirl;

public class Panier implements Serializable {

	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(Panier.class);

	private List<PricedCallGirl> callGirls = new ArrayList<PricedCallGirl>();

	public Panier() {
	}

	public List<PricedCallGirl> getCallGirls() {
		return callGirls;
	}

	public void addCallGirl(PricedCallGirl newCallGirl) {
		this.callGirls.add(newCallGirl);
	}

	public boolean containsCallGirl(String prenom) {
		for (PricedCallGirl callGirl : callGirls) {
			if (callGirl.getFirstName().equals(prenom)) {
				return true;
			}
		}
		return false;
	}
	
	public void removeCallGirl(String prenom) throws UnknowCallGirl {
		for (int i = 0; i < callGirls.size(); i++) {
			PricedCallGirl callGirl = callGirls.get(i);
			if (callGirl.getFirstName().equals(prenom)) {
				logger.debug("Call girl found, removing");
				callGirls.remove(i);
				return ;
			}
		}
		logger.warn("Call girl not found");
		throw new UnknowCallGirl();
	}

	public long getTotal() {
		long total = 0;
		for (PricedCallGirl callGirl : callGirls) {
			total += callGirl.getPrice();
		}
		return total;
	}
}
